<?php
class SP_Helpers_Curl
{
	private $handler;
	private $server="http://sms.aitk.ru";
	private $uri="data.php";
	private $user_agent="AITK Company";
	private $user='1';
	private $password='1';
	private $post_data;
	private $return_transfer=true;
	
	public function __construct($attr=null)
	{
		if(is_array($attr))
		{
			foreach($attr as $key => $value)
			{
				$this->$key=$value;
			}
		}
		$this->handler=curl_init();
		curl_setopt($this->handler, CURLOPT_URL,$this->getUrl());
		curl_setopt($this->handler,CURLOPT_RETURNTRANSFER,$this->return_transfer);
		curl_setopt($this->handler,CURLOPT_USERAGENT,$this->user_agent);
		curl_setopt($this->handler,CURLOPT_USERPWD,$this->getUserPassword());
	}
	
	public function setPostData($value)
	{
		$this->post_data=$value;
		curl_setopt($this->handler,CURLOPT_RAW_POST_DATA,$this->post_data);
		return $this;
	}
	
	public function setUserPassword($user,$password)
	{
		$this->user=$user;
		$this->password=$password;
		curl_setopt($this->handler,CURLOPT_USERPWD,$this->getUserPassword());
		return $this;
	}
	
	public function setReturnTransfer($value)
	{
		$this->return_transfer=(bool)$value;
		curl_setopt($this->handler,CURLOPT_RETURNTRANSFER,$this->return_transfer);
		return $this;
	}
	
	public function setUserAgent($value)
	{
		$this->user_agent=$value;
		curl_setopt($this->handler,CURLOPT_USERAGENT,$this->user_agent);
		return $this;
	}
	
	public function setUri($value)
	{
		$this->uri=$value;
		curl_setopt($this->handler, CURLOPT_URL,$this->getUrl());
		return $this;
	}
	
	public function setServer($value)
	{
		$this->server=$value;
		curl_setopt($this->handler, CURLOPT_URL,$this->getUrl());
		return $this;
	}
	
	public function getResponse()
	{
		return curl_exec($this->handler);
	}
	
	public function getUrl()
	{
		return $this->getServer().$this->getUri();
	}
	
	public function getServer()
	{
		return $this->server.'/';
	}
	
	public function getUri()
	{
		return $this->uri;
	}
	
	public function getUserPassword()
	{
		return $this->user.':'.$this->password;
	}
	
	
}